package com.fz.controller.system;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fz.aop.login.AnonymousAccess;
import com.fz.common.ResponseEntity;
import com.fz.beans.PageBeans;
import com.fz.dto.system.dept.DeptAdd;
import com.fz.dto.system.dept.DeptQuery;
import com.fz.dto.system.dept.DeptUpd;
import com.fz.entity.system.Dept;
import com.fz.service.system.DeptService;
import com.fz.vo.system.dept.DeptVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiSort;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

@RestController
@Api(tags = "部门管理")
@RequestMapping("/dept")
@ApiSort(value = 5)
@SuppressWarnings("unchecked")
public class DeptController {

    @Resource
    private DeptService deptService;

    @GetMapping("/findDeptList")
    @ApiOperation(value = "分页查询部门列表")
    @ApiOperationSupport(order = 1)
//    @PreAuthorize("@el.check('user:add')")
    @AnonymousAccess
    public ResponseEntity<IPage<DeptVo>> findDeptList(DeptQuery deptQuery, PageBeans pageBeans) throws Exception{
        return deptService.findDeptList(deptQuery,pageBeans.getPageNum(),pageBeans.getPageSize());
    }

    @PostMapping("/addDept")
    @ApiOperation(value = "新增部门")
    @ApiOperationSupport(order = 2)
    public ResponseEntity addDept(@RequestBody DeptAdd deptAdd) throws Exception{
        return deptService.addDept(deptAdd);
    }

    @PostMapping("/updateDept")
    @ApiOperation(value = "修改部门")
    @ApiOperationSupport(order = 3)
    public ResponseEntity updateDept(@RequestBody DeptUpd deptUpd) throws Exception{
        return deptService.updateDept(deptUpd);
    }

    @GetMapping("/findDeptBySelect")
    @ApiOperation(value = "部门下拉框")
    @ApiOperationSupport(order = 4)
    public ResponseEntity<List<Dept>> findDeptInSelect() throws Exception{
        return deptService.findDeptInSelect();
    }

}
